<div class="table-tools">
    <eq name="is_admin" value="1">
    <a href="__URL__/setUserIntegral" class="btn btn-info" title="设置用户钻石"><i class="fa fa-copy"></i>设置用户钻石 </a>
    <button onclick="deleteTestUser()" class="btn btn-primary" title="删除测试用户"><i class="glyphicon glyphicon-remove"></i>删除测试用户</button>
    <button onclick="deleteWinData()" class="btn btn-primary" title="删除胜率榜数据"><i class="glyphicon glyphicon-remove"></i>删除胜率榜数据</button>
    </eq>
    <!--<button type="button" class="btn btn-success" title="重新排序资源" onclick="sortQuestions()"><i class="fa fa-copy"></i> 重 排 </button>-->
    <form class="form-inline" method="post" action="__URL__/index" id="search_form"  role="form">
        <input type="hidden" name="pagenum" id="pagenum_hidden" value="{$page.pagenum}">
        <input type="hidden" name="count" value="{$recordcount}">
        <div class="form-group">
            <input type="text" name="id" value="{$id}" placeholder="请输入用户id">
            <input type="text" name="recommend_id" value="{$recommend_id}" placeholder="请输入推荐人id">
            <input type="text" name="last_one" value="{$last_one}" placeholder="请输入总代理id">
            <input type="text" name="nickname" value="{$nickname}" placeholder="请输入用户昵称">
            <select  name="region" id="region" class="form-control">
                <switch name="region">
                    <case value="-1">
                        <option value="-1" selected>战区</option>
                        <option value="1">微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <case value="0">
                        <option value="-1">战区</option>
                        <option value="1">微信</option>
                        <option value="0" selected>QQ</option>
                    </case>
                    <case value="1">
                        <option value="-1">战区</option>
                        <option value="1" selected>微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <default/>
                    <option value="-1" selected>战区</option>
                    <option value="1">微信</option>
                    <option value="0">QQ</option>
                </switch>
            </select>
            <select  name="systems_name" id="systems_name" class="form-control">
                <switch name="systems_name">
                    <case value="-1">
                        <option value="-1" selected>系统</option>
                        <option value="1">IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <case value="0">
                        <option value="-1">系统</option>
                        <option value="1">IOS</option>
                        <option value="0" selected>安卓</option>
                    </case>
                    <case value="1">
                        <option value="-1">系统</option>
                        <option value="1" selected>IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <default/>
                    <option value="-1" selected>系统</option>
                    <option value="1">IOS</option>
                    <option value="0">安卓</option>
                </switch>
            </select>
            <select  name="user_type" id="user_type" class="form-control">
                <switch name="user_type">
                    <case value="-1">
                        <option value="-1" selected>用户类型</option>
                        <option value="1">代理</option>
                        <option value="0">普通用户</option>
                    </case>
                    <case value="0">
                        <option value="-1">用户类型</option>
                        <option value="1">代理</option>
                        <option value="0" selected>普通用户</option>
                    </case>
                    <case value="1">
                        <option value="-1">用户类型</option>
                        <option value="1" selected>代理</option>
                        <option value="0">普通用户</option>
                    </case>
                    <default/>
                    <option value="-1" selected>用户类型</option>
                    <option value="1">代理</option>
                    <option value="0">普通用户</option>
                </switch>
            </select>

            <select  name="is_referee" id="is_referee" class="form-control">
                <switch name="is_referee">
                    <case value="-1">
                        <option value="-1" selected>是否裁判</option>
                        <option value="1">裁判</option>
                        <option value="0">普通用户</option>
                    </case>
                    <case value="0">
                        <option value="-1">是否裁判</option>
                        <option value="1">裁判</option>
                        <option value="0" selected>普通用户</option>
                    </case>
                    <case value="1">
                        <option value="-1">是否裁判</option>
                        <option value="1" selected>裁判</option>
                        <option value="0">普通用户</option>
                    </case>
                    <default/>
                    <option value="-1" selected>是否裁判</option>
                    <option value="1">裁判</option>
                    <option value="0">普通用户</option>
                </switch>
            </select>
            <select  name="is_register" id="is_register" class="form-control">
                <switch name="is_register">
                    <case value="-1">
                        <option value="-1" selected>是否完善资料</option>
                        <option value="1">已完善</option>
                        <option value="0">未完善</option>
                    </case>
                    <case value="0">
                        <option value="-1">是否完善资料</option>
                        <option value="1">已完善</option>
                        <option value="0" selected>未完善</option>
                    </case>
                    <case value="1">
                        <option value="-1">是否完善资料</option>
                        <option value="1" selected>已完善</option>
                        <option value="0">未完善</option>
                    </case>
                    <default/>
                    <option value="-1" selected>是否完善资料</option>
                    <option value="1">已完善</option>
                    <option value="0">未完善</option>
                </switch>
            </select>
            <button  type="button" onclick="gotoPage(0)">搜索</button>
        </div>
    </form>
    <p>用户列表</p>
</div>

<table id="users-table" class="table table-striped table-hover table-condensed datatable">
    <thead>

    <tr id="user_{$user.id}">
        <eq name="is_admin" value="1">
            <th width="110px">操作</th>
        </eq>
        <th >ID</th>
        <th>昵称</th>
        <th>手机号</th>
        <th>微信号</th>
        <th>钻石</th>
        <th>金币</th>
        <th>可提现金额</th>
        <th>真实浏览量</th>
        <th>显示浏览量</th>
        <th>累计浏览量</th>
        <th>所属代理id</th>
        <th>直推人id</th>
        <th>直推人数</th>
        <!--<th>游戏账号</th>-->
        <!--<th>所属系统</th>-->
        <!--<th>所属区域</th>-->
        <th>用户段位</th>
        <!--<th>比赛获胜数</th>-->
        <th>用户类型</th>
        <th>是否裁判</th>
        <eq name="is_admin" value="1">
        <th>代理提成</th>
        </eq>
        <!--<th>胜场</th>-->
        <!--<th>总场数</th>-->
        <th>注册时间</th>

        <!--<th width="80px">排序</th>-->
    </tr>
    </thead>
    <tbody>
    <volist name="list" id="user">
        <tr>
            <eq name="is_admin" value="1">
            <td width="110px">
                <eq name="user.user_type" value="0">
                    <div id="set_agent_{$user.id}">
                        <a onclick="setAgent('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="设置为代理"><span class="fa fa-pencil">设置代理</span>
                        </a>
                    </div>
                    <div id="cancel_agent_{$user.id}" hidden>
                        <a onclick="cancelAgent('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="取消代理"><span class="glyphicon glyphicon-remove">取消代理</span></a>
                    </div>
                    <else/>
                    <div id="set_agent_{$user.id}" hidden>
                        <a onclick="setAgent('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="设置为代理"><span class="fa fa-pencil">设置代理</span>
                        </a>
                    </div>
                    <div id="cancel_agent_{$user.id}">
                        <a onclick="cancelAgent('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="取消代理"><span class="glyphicon glyphicon-remove">取消代理</span></a>
                    </div>
                </eq>


                <eq name="user.is_referee" value="0">
                    <div id="set_referee_{$user.id}">
                        <a onclick="setReferee('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="设置为裁判"><span class="fa fa-pencil">设置裁判</span>
                        </a>
                    </div>
                    <div id="cancel_referee_{$user.id}" hidden>
                        <a onclick="cancelReferee('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="取消代理"><span class="glyphicon glyphicon-remove">取消裁判</span></a>
                    </div>
                    <else/>
                    <div id="set_referee_{$user.id}" hidden>
                        <a onclick="setReferee('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="设置为裁判"><span class="fa fa-pencil">设置裁判</span>
                        </a>
                    </div>
                    <div id="cancel_referee_{$user.id}">
                        <a onclick="cancelReferee('{$user.id}')"  data-user_type="{$user.user_type}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="取消裁判"><span class="glyphicon glyphicon-remove">取消裁判</span></a>
                    </div>
                </eq>
                <eq name="user.user_type" value="1">
                    <neq name="user.income" value="0">
                        <div>
                            <a onclick="clearTotalWithdraw('{$user.id}')"  class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="清空该代理可提现金额"><span class="fa fa-pencil">清空可提金额</span>
                            </a>
                        </div>
                    </neq>
                </eq>

                <neq name="user.pageviews" value="0">
                    <div>
                        <a onclick="clearPageviews('{$user.id}')"  class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="清空浏览量"><span class="fa fa-pencil">清空浏览量</span>
                        </a>
                    </div>
                </neq>

                <div>
                    <a href="__APP__/Admin/User/showBrowseLog?user_id={$user.id}"  class="btn btn-default btn-rounded btn-condensed btn-sm set-agent" title="查看浏览量"><span class="fa fa-pencil">查看浏览量</span>
                    </a>
                </div>
            </td>
            </eq>
            <!--<td width="50px"><input name='id[]' type="checkbox" value="{$user.id}" /></td>-->
            <td class="question-name">{$user.id}</td>
            <td class="question-name">{$user.nickname}</td>
            <td class="question-name">{$user.phone}</td>
            <td class="question-name">{$user.wechat_number}</td>
            <td class="question-name">{$user.integral}</td>
            <td class="question-name">{$user.gold}</td>
            <td class="question-name" id="user_income_{$user.id}">{$user.income}</td>
            <td class="question-name" >{$user.pageviews}</td>
            <td class="question-name" id="user_pageviews_{$user.id}">{$user.show_pageviews}</td>
            <td class="question-name">{$user.count_pageviews}</td>
            <td class="question-name">{$user.last_one}</td>
            <td class="question-name">{$user.recommend_id}</td>
            <td class="question-name">{$user.recommend}</td>

            <td class="question-name">
                <select name="level" name="level" data-id="{$user.id}" onchange="ajaxUpdateField(this);" id="level" data-am-selected="">
                    <switch name="user.level">
                        <case value="0">
                            <option value="0" selected>用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="1">
                            <option value="0" >用户未修改</option>
                            <option value="1" selected>青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="2">
                            <option value="0" >用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2" selected>白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="3">
                            <option value="0" >用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3" selected>黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="4">
                            <option value="0" >用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4" selected>铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="5">
                            <option value="0" >用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5" selected>钻石</option>
                            <option value="6">星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="6">
                            <option value="0">用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6" selected>星耀</option>
                            <option value="7">王者</option>
                        </case>
                        <case value="7">
                            <option value="0">用户未修改</option>
                            <option value="1">青铜</option>
                            <option value="2">白银</option>
                            <option value="3">黄金</option>
                            <option value="4">铂金</option>
                            <option value="5">钻石</option>
                            <option value="6">星耀</option>
                            <option value="7" selected>王者</option>
                        </case>
                        <default/>
                        <option value="0" selected>用户未修改</option>
                        <option value="1">青铜</option>
                        <option value="2">白银</option>
                        <option value="3">黄金</option>
                        <option value="4">铂金</option>
                        <option value="5">钻石</option>
                        <option value="6">星耀</option>
                        <option value="7">王者</option>
                    </switch>

                </select>
            </td>
            <!--<td class="question-name">{$user.win_number}</td>-->
            <td class="question-name" id="user_type_{$user.id}">
                <switch name="user.user_type">
                    <case value="0">
                        普通用户
                    </case>
                    <case value="1">
                        代理
                    </case>
                </switch>
            </td>
            <td class="question-name" id="is_referee_{$user.id}">
                <switch name="user.is_referee">
                    <case value="0">
                        普通用户
                    </case>
                    <case value="1">
                        裁判
                    </case>
                </switch>
            </td>
            <eq name="is_admin" value="1">
            <td class="question-name">
                <eq name="user.user_type" value="1">
                    <input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                           onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                           onchange="ajaxUpdateField(this);" name="rebate_percentage" size="4" data-table="t_user"
                           data-id="{$user.id}" value="{$user.rebate_percentage}"/>
                </eq>
            </td>
            </eq>
            <!--<td class="question-name">-->
                <!--<input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"-->
                       <!--onpaste="this.value=this.value.replace(/[^\d.]/g,'')"-->
                       <!--onchange="ajaxUpdateField(this);" name="win_number" size="4" data-table="t_user"-->
                       <!--data-id="{$user.id}" value="{$user.win_number}"/>-->
            <!--</td>-->
            <!--<td class="question-name">-->
                <!--<input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"-->
                       <!--onpaste="this.value=this.value.replace(/[^\d.]/g,'')"-->
                       <!--onchange="ajaxUpdateField(this);" name="total_number" size="4" data-table="t_user"-->
                       <!--data-id="{$user.id}" value="{$user.total_number}"/>-->
            <!--</td>-->
            <td class="question-name">{$user.create_time}</td>


            <!--<td width="80px"><input name="sort[{$user.id}]" class="sort-input" type="text" value="{$user.sort}" /></td>-->
        </tr>
    </volist>
    </tbody>
</table>
<nav style="float:right">
    <spen class="total">共 {$recordcount}条记录</spen>
    <div class="fr">
        <ul class="pagination">
            <eq name="page['pagenum']" value="1">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('1')">«</a></li>
            <foreach name="page.pagenums" item="vo">
                <eq name="page['pagenum']" value="$vo">
                    <li class="active"><a href="#">{$vo}</a></li>
                    <else/>
                    <li><a href="#" onclick="gotoPage('{$vo}')">{$vo}</a></li>
                </eq>
            </foreach>
            <eq name="page['pagenum']" value="$page.endPage">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('{$page.totalpage}')">»</a></li>
        </ul>
    </div>
</nav>
<!-- Modal -->
<div class="modal fade" id="my-alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body" id="hint_content">
            </div>
            <div class="modal-footer">
                <button type="button" id="close_btn" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="save-change" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/layer/layer.js"></script>
<script>
    //删除测试用户
    function deleteTestUser(){
        $("#hint_content").empty().append('是否清空测试用户？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/ajaxDeleteTestUser",
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }
    function deleteWinData(){
        $("#hint_content").empty().append('是否清空胜率榜的数据？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/ajaxDeleteWinData",
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }
    function setAgent(user_id){
        $("#hint_content").empty().append('是否将当前用户设置为代理？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/setAgent",
                data: {user_id: user_id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#set_agent_'+user_id).hide();
                        $('#cancel_agent_'+user_id).show();
                        $('#user_type_'+user_id).empty().append('代理');
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }

    function setReferee(user_id){
        $("#hint_content").empty().append('是否将当前用户设置为裁判？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').on('click', function(){
            window.location.href = '__APP__/Admin/User/setReferee?user_id='+user_id;
        })
    }

    function cancelReferee(user_id){
        $("#hint_content").empty().append('是否取消当前用户的裁判权限？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/ajaxCancelReferee",
                data: {user_id: user_id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#set_referee_'+user_id).show();
                        $('#cancel_referee_'+user_id).hide();
                        $('#is_referee_'+user_id).empty().append('普通用户');
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }

    function ajaxUpdateField(obj) {
        var table = $(obj).data('table');
        var id = $(obj).data('id');
        var field = $(obj).attr('name').replace(/field_/ig, ""); // 字段名字
        var value = $(obj).val();
        console.info(id);
        $.ajax({
            type: 'POST',
            data: {table: table, id: id, field: field, value: value},
            url: "__URL__/updateField",
            dataType: "json",
            success: function (data) {
                console.info(data);
//                $("#update_field").empty().append(data.message);
//                $("#my_update_field").modal();
            },
            error: function (data) {
                $(".am-modal-bd").empty().append("请求超时！");
                $("#my-alert").modal();
            }
        });
    }

    function cancelAgent(user_id){
        $("#hint_content").empty().append('是否将当前用户设置为普通用户？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/cancelAgent",
                data: {user_id: user_id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#set_agent_'+user_id).show();
                        $('#cancel_agent_'+user_id).hide();
                        $('#user_type_'+user_id).empty().append('普通用户');
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }

    function clearTotalWithdraw(user_id){
        $("#hint_content").empty().append('是否清空该代理的可提现金额？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/ajaxClearIncome",
                data: {user_id: user_id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#user_income_'+user_id).empty().append(0);
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }
    function clearPageviews(user_id){
        $("#hint_content").empty().append('是否请空该用户的浏览量？');
        $("#my-alert").modal('show');
        $('#close_btn').unbind('click');
        $('#save-change').unbind('click');
        $('#save-change').on('click', function(){
            $.ajax({
                type: "POST",
                url: "__URL__/ajaxClearPageviews",
                data: {user_id: user_id},
                dataType: "json",
                success: function (data) {
                    console.info(data);
                    $("#hint_content1").empty().append(data.message);
                    $("#my-alert1").modal('show');
                    if (data.success) {
                        $('#user_pageviews_'+user_id).empty().append(0);
                    }
                },
                error: function (data) {
                    $("#hint_content1").empty().append('服务器忙');
                    $("#my-alert1").modal('show');
                }
            });
        })
    }

    function gotoPage(pagenum) {
        //提交form
        $('#pagenum_hidden').val(pagenum);
        $('#search_form').submit();
    }
</script>